﻿using System;
using System.Windows;
using System.Windows.Controls;
using Bookvar.ObjectModel;
using Bookvar.UI.ViewModel.LiveImages;

namespace Bookvar.UI.DragDrop
{
    public class ImageViewerDragSourceAdvisor : DragSourceAdvisorBase
    {
        public override DragDropEffects SupportedEffects
        {
            get { return DragDropEffects.Move | DragDropEffects.Copy; }
        }

        public override bool IsDraggable( UIElement dragElement )
        {
            return dragElement is Image;
        }

        public override bool UseOriginalSource
        {
            get { return true; }
        }

        public override DataObject GetDataObject( UIElement draggedElement, Point offsetPoint )
        {
            base.GetDataObject( draggedElement, offsetPoint );
            var image = draggedElement as Image;
            if ( image != null )
            {
                var imageInfo = (ImageInfo) image.DataContext;
                var size = new Size( image.ActualWidth, image.ActualHeight );
                var liveImageInfo = new LiveImageInfo( imageInfo, image.Source, size );
                Data.SetData( BookvarDataFormats.LiveImageInfo.Name, liveImageInfo );
            }
            return Data;
        }
    }
}
